import logging,HTMLTestRunner_cn,yagmail,time

# 时间戳
t = time.strftime('%Y%m%d%H%M%S',time.localtime())
class Tools:

    # 报告
    def report(self):
        report = HTMLTestRunner_cn.HTMLTestRunner(open(f'{t}baidu.html','wb'),title='百度功能测试报告')
        return report
    # 日志
    def log(self):
        logging.basicConfig(
            level=logging.DEBUG,
            filename=f'{t}baidufirstpagewebtestlog.txt',
            format='%(name)s %(message)s %(asctime)s %(thread)d',
            filemode='a'
        )
    # 邮件
    def email(self):
        email = yagmail.SMTP(user='3516922232@qq.com',password='sauvhzrimccccjbi',host='smtp.qq.com')
        email.send(to='3516922232@qq.com',subject='百度WebFirstPage Ui自动化测试报告',contents='附件如下',
                   attachments=[f'{t}baidu.html',f'{t}baidufirstpagewebtestlog.txt'])
        # 关闭邮箱
        email.close()